//
//  EventSearch.swift
//  MusicApp
//
//  Created by tianjs on 2023/4/21.
//

import SwiftUI

struct EventSearch: View {
    @State private var keyword: String = ""
    @State private var distance: String = "10"
    @State private var category: String = "Default"
    @State private var location: String = ""
    @State private var autoLocation: Bool = false
    
    private var menuList: Array = ["Default", "Music", "Sports", "Arts & Theatre", "Film", "Miscellaneous"]
    
    var body: some View {
//        NavigationView {
            ScrollView {
                VStack(alignment: .leading) {
                    Group {
                        HStack {
                            Text("Keyword:")
                                .foregroundColor(.secondary)
                            TextField("Required", text: $keyword)
                        }
                        Divider()
                        
                        HStack {
                            Text("Distance:")
                                .foregroundColor(.secondary)
                            TextField("Distance", text: $distance)
                        }
                        Divider()
                        
                        HStack {
                            Text("Category:")
                                .foregroundColor(.secondary)
                            
                            Spacer()
                            
                            Menu {
                                Section {
                                    ForEach(0..<menuList.count, id: \.self) { index in
                                        Button {
                                            category = menuList[index]
                                        } label: {
                                            HStack(alignment: .firstTextBaseline) {
                                                if (category == menuList[index]) {
                                                    Image(systemName: "checkmark")
                                                }
                                                  Text(menuList[index])
                                            }
                                            
                                        }
                                    }
                                }
                            } label: {
//                                Text("category")
                                TextField("Required", text: $category)
                                    .multilineTextAlignment(.trailing)
//                                    .textFieldStyle(.)
                            }

                        }
                        Divider()
                        
                        HStack {
                            Text("Location:")
                                .foregroundColor(.secondary)
                            TextField("Required", text: $location)
                        }
                        Divider()
                        
                        HStack {
                            Text("Auto-detect my location")
                                .foregroundColor(.secondary)
                            
                            Spacer()
                            
                            Toggle("", isOn: $autoLocation)
                        }
                        Divider()
                    }
                    
                    Group {
                        HStack {
                            Button {
                                
                            } label: {
                                Text("Submit")
                                    .foregroundColor(.white)
                                    .padding([.leading, .trailing], 30)
                                    .padding([.top, .bottom], 15)
                                    .background(rgb(r: 154, g: 154, b: 154))
                                    .cornerRadius(6)
                            }
                            
                            Spacer()
                            
                            Button {
                                
                            } label: {
                                Text("Clear")
                                    .foregroundColor(.white)
                                    .padding([.leading, .trailing], 30)
                                    .padding([.top, .bottom], 15)
                                    .background(.blue)
                                    .cornerRadius(6)
                            }
                        }
                        .padding([.leading, .trailing], 30)
                        .padding([.top, .bottom], 20)
                        
                    }
                        
                }
                .padding([.leading, .trailing], 15)
                .padding([.top, .bottom], 5)
                .background(Color(.white))
                .cornerRadius(6)
                
            }
            .background(rgb(r: 239, g: 238, b: 244))
            .padding(0)
            .navigationTitle("Event Search")
            .toolbar {
                Button {
                    
                } label: {
                    Image(systemName: "heart.circle")
                        .foregroundColor(Color(.systemBlue))
                }

            }
//        }
    }
}

struct EventSearch_Previews: PreviewProvider {
    static var previews: some View {
        EventSearch()
    }
}
